package com.winter.service;

import com.winter.mapper.CaBondCrPriValuMapper;
import com.winter.mapper.CaBondCredMoneyMapper;
import com.winter.mapper.CaBondNewIssMoneyMapper;
import com.winter.mapper.CaCpMapper;
import com.winter.mapper.CaShiborMoneyMapper;
import com.winter.mapper.IindudyReportPolicyMapper;
import com.winter.mapper.NewsMapper;
import com.winter.util.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeService {

    @Autowired
    public IindudyReportPolicyMapper iindudyReportPolicyMapper;

    @Autowired
    public NewsMapper newsMapper;

    @Autowired
    private CaBondCrPriValuMapper caBondCrPriValuMapper;

    @Autowired
    private CaShiborMoneyMapper caShiborMoneyMapper;

    @Autowired
    private CaBondCredMoneyMapper caBondCredMoneyMapper;

    @Autowired
    private CaBondNewIssMoneyMapper caBondNewIssMoneyMapper;

    @Autowired
    private CaCpMapper caCpMapper;

    /**
     * 10点前显示的是每日早餐，10点之后显示的是新闻资讯的
     */
    public Result homeMsg() {
        SimpleDateFormat df = new SimpleDateFormat("HH");
        String format = df.format(System.currentTimeMillis());
        if (Integer.valueOf(format) >= 10) {
            List<Map<String, Object>> maps = iindudyReportPolicyMapper.selectByList();
            return Result.success(maps);
        } else {
            // 获取最新时间一条 每日早餐
            Map<String, Object> map = iindudyReportPolicyMapper.selectByLatestTime();
            map.put("type", "每日早餐");
            return Result.success(map);
        }
    }

    public Result research() {
        // 债券估值
        String caBondCrPriValu = caBondCrPriValuMapper.newestTime();

        // shibor报价
        String caShiborMoney = caShiborMoneyMapper.newestTime();

        //  评级变动
        String caBondCredMoney = caBondCredMoneyMapper.newestTime();

        // 新债发行
        String caBondNewIssMoney = caBondNewIssMoneyMapper.newestTime();

        //票据报价
        String caCp = caCpMapper.newestTime();

        Map<String, Object> map = new HashMap<>();

        map.put("债券估值", caBondCrPriValu);
        map.put("Shibor报价", caShiborMoney);
        map.put("评级变动", caBondCredMoney);
        map.put("新债发行", caBondNewIssMoney);
        map.put("票据报价", caCp);

        return Result.success(map);
    }
}
